package educational.cad.model;

/**
 * This class represents physical entity of a package pin.
 * 
 * @author Sergey Seroshtan
 * 
 */
public final class Pin implements Comparable<Pin> {

	public Pin(int number, Position position) {
		if (number < 0) {
			throw new IllegalArgumentException("Pin number is negative.");
		}
		if (position == null) {
			throw new IllegalArgumentException("Pin position is undefined.");
		}
		this.number = number;
		this.position = position;
	}

	public int number() {
		return number;
	}

	public Position position() {
		return position;
	}

	private final int number;
	private final Position position;

	private static final int LESS = -1;
	private static final int EQUAL = 0;
	private static final int GREATER = 1;

	@Override
	public int compareTo(Pin another) {

		if (this.number < another.number) {
			return LESS;
		}
		if (this.number == another.number) {
			return EQUAL;
		}
		if (this.number > another.number) {
			return GREATER;
		}
		throw new IllegalStateException("Unreachable code.");
	}

	@Override
	public boolean equals(Object another) {
		return this.compareTo((Pin)another) == EQUAL;
	}

	@Override
	public int hashCode() {
		int hash = 17;
		hash = 31 * hash + number;
		hash = 31 * hash + position.hashCode();
		return hash;
	}
}
